import Vue from 'vue'
import Vuex from 'vuex' 
import createPersistedState from "vuex-persistedstate";
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        // list: JSON.parse(localStorage.getItem('baocun')) || [],
        list:[{id:1,name:'hahaha',isDone:false},{id:2,name:'hahaha2',isDone:true}],
        count:1,
        zhenlist:{},
        getsel:'',
      },

      mutations: {
        changeList(state,val){
           state.list = state.list.filter(ele => ele.id !== val)
               },
        add(state,val){
            state.list.unshift(val)
        },

        qiehuan(state,val){   
            // 保存状态    
            state.getsel = val
            console.log(state.getsel);
        },
        clickall(state){
            state.list = state.list.filter(ele => !ele.isDone)
        }
     },

     getters: {
        count(state) {
          return state.list.filter(ele => !ele.isDone).length
        },
        zhenlist(state){
            if(state.getsel === 'yes'){
                return state.list.filter(ele => ele.isDone)
               }else if(state.getsel === 'no'){
               return state.list.filter(ele => !ele.isDone)
               }else{
                 return state.list
               }
        },

      },

      plugins: [createPersistedState({
        key: "myVuex",
        paths: ["zhenlist",'list'],
        storage: window.localStroage,
      })]
     
})
export default store 